﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using ZhaoxiLearningWpf.Common;
using ZhaoxiLearningWpf.Model;

namespace ZhaoxiLearningWpf.ViewModel
{
    public class MainViewModel : NotifyBase
    {
        public UserModel UserInfo { get; set; } = new UserModel();


        private string searchText;
        public string SearchText {
            get {
                return searchText;
            }
            set {
                searchText = value;
                this.DoNotify();
            }
        }


        private FrameworkElement mainContent;
        public FrameworkElement MainContent {
            get {
                return mainContent;
            }
            set {
                mainContent = value;
                this.DoNotify();
            }
        }

        public CommandBase NavContentChange { get; set; }


        public MainViewModel()
        {
            NavContentChange = new CommandBase();
            NavContentChange.DoExecute = NavChanged;
            NavContentChange.DoCanExecute = o => true;

            NavChanged("FirstPageView");
        }

        private void NavChanged(object o)
        {
            Type type = Type.GetType("ZhaoxiLearningWpf.View."+o.ToString());
            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
            this.MainContent=(FrameworkElement)constructor.Invoke(null);
        }
    }
}
